<?php
if(PERMISSION != "F")
{
	redirectPage("index.php?module=logout");
	exit();
}
?>
<?php include('includes/header.php'); ?>

<div id="content">
          
	<div id="stage-2" style="display: block">
		<?php include('includes/header_games.php'); ?>
		<div style="clear: both">&nbsp;</div>
		<div class="title">
			<div class="t-1" style="float:left;width: 40px"><strong>No.</strong></div>
			<div class="t-1" style="float:left;width: 100px"><strong>WWID</strong></div>
			<div class="t-1" style="float:left;width: 150px"><strong>User</strong></div>
			<div class="t-1" style="float:left;width: 55px"><strong>Played Times</strong></div>
			<div class="t-1" style="float:left;width: 55px"><strong>Total Words</strong></div>
			<div class="t-1" style="float:left;width: 65px"><strong>Correct</strong></div>
			<div class="t-1" style="float:left;width: 80px"><strong>Language</strong></div>
			<div class="t-1" style="float:left;width: 110px"><strong>Time Played</strong></div>
			<div class="t-1" style="float:left;width: 180px"><strong>Played On</strong></div>
			<div style="float:left;width: 70px">&nbsp;</div>
			<div style="clear: both">&nbsp;</div>
		</div>
		<?php
		if($db_type == "mysql")
		{
		$sql = "SELECT (SELECT COUNT(*) FROM games g Where g.user_id = games.user_id) AS `play_times`, game_id,games.user_id,unique_id,full_name,lang,crossword_word_count,user_word_correct,user_time,end_time
 FROM games INNER JOIN users ON games.user_id = users.user_id 
 ORDER BY games.user_word_correct DESC, user_time ASC, `play_times` ASC LIMIT 100";
		}
		else
		{
			$sql = "SELECT TOP(100) (SELECT COUNT(*) FROM games g Where g.user_id = games.user_id) AS play_times, game_id,games.user_id,unique_id,full_name,lang,crossword_word_count,user_word_correct,user_time,end_time
 FROM games INNER JOIN users ON games.user_id = users.user_id 
 ORDER BY games.user_word_correct DESC, user_time ASC, play_times ASC";
		}
		
		$arr_user_id = array();
				
		$result  = $db_mysql->get_array($sql);
		$No = 0;
		foreach($result as $row)
		{
			$user_id = $row["user_id"];
			if(!in_array($user_id, $arr_user_id))
			{
				$No++;
				$id = $row["game_id"];
				$unique_id = $row["unique_id"];
				$full_name = $row["full_name"];
				$lang = strtoupper($row["crossword_lang"]);
				$play_times = $row["play_times"];
				$word_count = $row["crossword_word_count"];
				$word_correct = $row["user_word_correct"];
				$user_time = seconds_to_time($row["user_time"]);
				$date_created = format_date($row["end_time"], "d/m/Y h:i:s");
		?>
		<div class="row">
			<div class="r-1" style="float:left;width: 40px"><?=$No?></div>
			<div class="r-1" style="float:left;width: 100px">&nbsp;<?=$unique_id ?></div>
			<div class="r-1" style="float:left;width: 150px">&nbsp;<?=$full_name ?></div>
			<div class="r-1" style="float:left;width: 55px"><?=$play_times ?></div>
			<div class="r-1" style="float:left;width: 55px"><?=$word_count ?></div>
			<div class="r-1" style="float:left;width: 65px"><?=$word_correct ?></div>
			<div class="r-1" style="float:left;width: 80px"><?=$lang ?></div>
			<div class="r-1" style="float:left;width: 110px"><?=$user_time ?></div>
			<div class="r-1" style="float:left;width: 180px"><?=$date_created?></div>
			<div style="float:left;width: 70px">
				<a href="index.php?module=games_view&id=<?=$id?>">Details</a>
			</div>
			<div style="clear: both">&nbsp;</div>
		</div>
		<?php
			}
			$arr_user_id[] = $user_id;
		}
		?>
		
		
    </div>
</div>

